Skip to content

fix(github): Do not stack pull requests from the trunk or on looping base branches - #3153

Merged
thomasjiangcy merged 2 commits into
mainfrom
fix/github-stack-trunk-loop
Nov 11, 2026
Merged

thomasjiangcy merged 2 commits into
mainfrom
fix/github-stack-trunk-loop

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

In getsentry/sentry-docs, a scheduled automation opened the weekly sync PR getsentry/sentry-docs#20685 (master → java-v9) while the long-lived collection PR getsentry/sentry-docs#19963 (java-v9 → master) was open. github_createPullRequest treated #19963 as the PR below the sync PR. The stack walk then went java-v9 → master → java-v9, found the sync PR again at each step, and ran until MAX_STACK_DEPTH. It created stack 20686, which lists both PRs again and again. When the sync PR merged, GitHub retargeted #19963 onto java-v9, its own head, and marked it merged. master did not change, but the collection PR had to be opened again (getsentry/sentry-docs#20718).

Changes in stackGitHubPullRequest:

  • Do not stack a PR whose head is the default branch. A sync from the trunk is not stacked work.
  • Stop the walk at the default branch.
  • Do not stack when the walk reaches a PR that is already in the chain.

The GitHub plugin docs now list these cases.

Open question: a PR into a long-lived integration branch, such as feat/x → java-v9, still stacks on the collection PR (java-v9 → master). If someone merges that stack as one group, the collection branch could land on the trunk early. A fix probably needs a rule for when the PR below is a long-lived branch, for example a draft PR, so this PR does not change it.

via alexander.dinauer.

--

View Session [Sentry]

…base branches

A weekly sync PR (master -> java-v9) was opened while a long-lived
collection PR (java-v9 -> master) was open. The stack walk followed
java-v9 -> master -> java-v9 until the depth limit and created a stack
that repeated both PRs. Merging the sync PR then retargeted the
collection PR onto its own head, so GitHub marked it merged.

Skip stacking when the head is the default branch, stop the walk at the
default branch, and give up when the walk reaches a PR it already saw.

Co-Authored-By: Alexander Dinauer <alexander.dinauer@sentry.io>
@vercel

vercel Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 11, 2026 6:37am UTC

Request Review

@sentry-junior sentry-junior Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is right for the sentry-docs case. The head.ref === trunk guard stops the weekly sync PR from stacking, and the chain.includes guard catches other loops. I ran tests/github-plugin.test.ts locally and all 120 tests pass. When I removed each guard, its own case failed.

One gap before this lands:

  • No test covers the branch !== trunk stop in the walk. When I removed it, all 120 tests still passed. This guard matters while a sync PR is open. Take B (feat/b → feat/a), A (feat/a → main), and an open sync PR S (main → java-v9). Without the guard, the walk looks up head=main, finds S, and calls stack create with [S, A, B] when java-v9 has no open PR. When the collection PR is open, the loop guard returns early and the valid stack is silently skipped. Please add a case where the head=main lookup returns an open PR, and assert that stack create gets [A, B].

Also, the comment No parent: \branch` is the trunk.` is now wrong. The loop no longer queries the trunk, so no parent means the base branch has no open PR.

I agree that the long-lived integration branch question (feat/x → java-v9 stacking on the collection PR) belongs in a follow-up.

… open

The stacking test returned no open pull request for the trunk, so it
passed with or without the stop at the trunk. Give the trunk an open sync
pull request so the test fails if the walk adds it to the stack.

Co-Authored-By: Thomas Jiang <20501235+thomasjiangcy@users.noreply.github.com>
@thomasjiangcy
thomasjiangcy merged commit d071489 into main Nov 11, 2026
45 checks passed
@thomasjiangcy
thomasjiangcy deleted the fix/github-stack-trunk-loop branch November 11, 2026 06:49

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 7c74ace5 Deployed Nov 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant